import os
import jwt
import time

data = """
    FlFVVVIxGljZW5zZWVOYW1lIjoiZ2hib2tlIiwiYXNzaWduZWVOYW1lIjoiIiwi
    YXNzaWduZWVFbWFpbCI6eiIsImxpY2Vuc2VSZXN0cmljdGlvbiI6IiIsImNoZWN
    rQ29uY3VycmVudFVzZSI6ZmFsc2UsInByb2R1Y3RzhjfdJUDGujhujUIuiJuIUy
    SwiaXNBdXRvUHJvbG9uZ2F0ZWQiOmZhbHNlfQsfg1iV7BApbaNqv0Q5yUnAphUm
    h66QhkDRX+qPL09cpuEicBqiPOBxmVLLCVUpkxhrNyfmOtat2LcHwcX/NHkYXpM
    SwDDaXNBdXRvUHJvbG9uZ2F0ZWQiOmZhbHNlfQsfg1iV7BApbaNqv0Q5yUnAphU
"""


def encode_jwt(kwargs: dict) -> str:
    # exp = int(time.time() + 60 * 60 * 24 * 30)
    # kwargs["exp"] = exp
    return jwt.encode(payload=kwargs, key=data)


def decode_jwt(salt: str) -> dict:
    try:
        info = jwt.decode(jwt=salt, key=data, verify=False, algorithms='HS256')
        info["code"] = 200
        return info
    except jwt.ExpiredSignatureError:
        return {"code": 500}
    except jwt.InvalidTokenError:
        return {"code": 500}

